<style>
.notic{
    line-height: 18px;
    color: #AAA;
    margin-top: 8px;
    clear: both;
} 
</style>
<form method="post" action="/oss/?r=codePool/doEdit">
    <{include file='../common_params.tpl'}>
    <input type="hidden" name="id" value="<{$info.id}>" />

    <div class="box box-black">
        <div class="box-body">
            <table class="table table-bordered">
                <colgroup>
                    <col style="width: 20%;"></col>
                    <col style="width: 80%;"></col>
                </colgroup>
                
                <tr>
                    <th class="th-label">礼包种类</th>
                    <td>
                        <select class="form-control inline" name="classify" style="width: 150px;" readonly="readonly" onfocus="this.defaultIndex=this.selectedIndex;" onchange="this.selectedIndex=this.defaultIndex;">
                            <{foreach from=$classifyList item=item key=key}>
                        		<option <{if $info.classify == $key }>selected<{/if}> value="<{$key}>"><{$item}></option>
                        	<{/foreach}>
                        </select>
                    </td>
                </tr>
                
                <!--<tr class="type-info" for="1">
                    <th class="th-label">生成类型</th>
                    <td>
                        <select class="form-control inline" name="bag_id" style="min-width: 150px;">
                        	<option value="">请选择</option>
                            <{foreach from=$bagList item=item key=key}>
                        		<option value="<{$key}>"><{$item}></option>
                        	<{/foreach}>
                        </select>
                    </td>
                </tr>-->
                
                <tr class="type-info" for="1">
                    <th class="th-label">礼包ID</th>
                    <td>
                        <input type="number" class="form-control inline" value="<{$info.bag_id}>" style="width: 150px;" name="bag_id" />
                    </td>
                </tr>
                
                
                <tr class="type-info" for="1">
                    <th class="th-label">生成数量</th>
                    <td>
                        <input type="number" max="20000" value="<{$info.code_num}>" class="form-control inline" style="width: 150px;" name="code_num" readonly="readonly"/>
                    </td>
                </tr>
                
                <tr class="type-info" for="1">
                    <th class="th-label">生成key</th>
                    <td>
                        <input type="text" class="form-control inline" value="<{$info.code_key}>" style="width: 150px;" name="code_key" readonly="readonly"/>
                    </td>
                </tr>
                
                <tr class="type-info" for="1">
                    <th class="th-label">同账号可领取</th>
                    <td>
                        <select class="form-control inline" name="is_same_accoun" style="min-width: 150px;" readonly="readonly" onfocus="this.defaultIndex=this.selectedIndex;" onchange="this.selectedIndex=this.defaultIndex;">
                        	<option <{if $info.is_same_accoun == 1 }>selected<{/if}> value="1">不可以</option>
                            <option <{if $info.is_same_accoun == 2 }>selected<{/if}> value="2">可以</option>
                        </select>
                    </td>
                </tr>
                
                <tr class="type-info" for="1" id='is_same_role'> 
                    <th class="th-label">同角色可领取</th>
                    <td>
                        <select class="form-control inline" name="is_same_role" style="min-width: 150px;" readonly="readonly" onfocus="this.defaultIndex=this.selectedIndex;" onchange="this.selectedIndex=this.defaultIndex;">
                        	<option <{if $info.is_same_role == 1 }>selected<{/if}> value="1">不可以</option>
                            <option <{if $info.is_same_role == 2 }>selected<{/if}> value="2">可以</option>
                        </select>
                    </td>
                </tr>
                
                <tr class="type-info" for="1" id="limit_time">
                    <th class="th-label">重复领取时间限制</th>
                    <td>
                        <input type="number" readonly="readonly" value="<{$info.limit_time}>" class="form-control inline" style="width: 150px;" name="limit_time" value="0"/>
                        <span>0为没限制(单位：小时)</span>
                    </td>
                </tr>
                
                <tr class="type-info" for="1">
                    <th class="th-label">领取等级限制</th>
                    <td>
                        <input type="number" readonly="readonly" value="<{$info.limit_grade}>" class="form-control inline" style="width: 150px;" name="limit_grade" value="0"/>
                        <span>0为没限制</span>
                    </td>
                </tr>

                <tr class="type-info" for="1">
                    <th class="th-label">生效时间</th>
                    <td>
                        <input type="text" readonly="readonly" class="form-control inline time"  value="<{$info.start_time}>" style="width: 150px;" name="start_time" />
                        <span>空为无限制</span>
                    </td>
                </tr>
                
                <tr class="type-info" for="1">
                    <th class="th-label">失效时间</th>
                    <td>
                        <input type="text" readonly="readonly" class="form-control inline time" value="<{$info.end_time}>" style="width: 150px;" name="end_time" />
                        <span>空为无限制</span>
                    </td>                    
                </tr>
                
                <tr>
                    <th class="th-label">是否全渠道</th>
                    <td>
                    	<div style="padding-top: 5px;">
                    		<{if $info.is_all_channel == 2 }>是<{/if}>
                    		<{if $info.is_all_channel == 1 }>否<{/if}>
                    		<input type="hidden" name="is_all_channel" value="<{$info.is_all_channel}>"/>
                    		<!--<input type="radio" readonly="readonly" name="is_all_channel" id="is_all_channel1" value="2" <{if $info.is_all_channel == 2 }>checked<{/if}>/>是
                    		&nbsp;&nbsp;
                    	    <input type="radio" readonly="readonly" name="is_all_channel" id="is_all_channel2" value="1" <{if $info.is_all_channel == 1 }>checked<{/if}>/>否-->
                    	</div>	
                    </td>
                </tr>
                
                <tr class="select_channel">
                    <th class="th-label">请选择渠道</th>
                    <td>
                    	<p class="notic">
                        <a onclick="searchChannel()" class="ncap-btn"><i class="fa fa-search"></i>选择渠道</a>
                        </p>
                        <div id="selected_group_channel">
                        	<{foreach from=$channel_list item=item key=key}>
                        		<div style="float: left;margin-right: 20px">
                        			<div class="ys-btn-close" style="color:red;top: 15px;left: 172px;">×</div>
                                    <input type="hidden" name="channel_id[]" value="<{$item.channel_id}>"/><{$item.channel_name}>
                        		</div>
                        	<{/foreach}>
                        </div>
                    </td>
                </tr>
                
                <tr class="type-info" for="1" id='is_same_role'> 
                    <th class="th-label">状态</th>
                    <td>
                        <select class="form-control inline" name="status" style="min-width: 150px;">
                        	<option <{if $info.status == 1 }>selected<{/if}> value="1">启用</option>
                            <option <{if $info.status == 2 }>selected<{/if}> value="2">关闭</option>
                        </select>
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">备注</th>
                    <td><textarea class="form-control" name="desc" rows="10"><{$info.desc}></textarea></td>
                </tr>


            </table>
        </div>

        <div class="box-footer">
            <a href="<{$backUrl}>" class="btn btn-default">返回</a>
            <button type="submit" name="sub" class="btn btn-default pull-right">保存</button>
            <input type="hidden" name="page" value="<{$page}>" />
        </div>
    </div>
</form>

<script>
    $(function(){
//  	$(".time").datetimepicker({
//          format: 'yyyy-mm-dd hh:ii',
//      });
        
//      $('select[name="classify"]').change(function(){
//      	var g = $('input[name="g"]').val();
//	        var url = '?r=codePool/getBag&g='+g;
//	        var classify = $('select[name="classify"]').val();
//	        if(classify == ''){
//	        	var option = '';	
//				option += "<option value=''>请选择</option>";
//				$('select[name="bag_id"]').empty();
//				$('select[name="bag_id"]').append(option);
//	        	return false;
//	        }
//
//	        $.ajax({
//	        	type : 'POST',
//	        	url : url,
//	        	data : {'classify':classify},
//		        dataType :'JSON',
//		        success : function(res){
//		        	if(res.status == 1){
//		        		var option = '';	
//					    option += "<option value=''>请选择</option>";
//					    
//					    var data = res.data;
//					    for(let index in data) {
//					    	console.log(index,data[index]);
//					    	option += "<option value='"+index+"'>"+data[index]+"</option>";
//					    }						
//
//					    $('select[name="bag_id"]').empty();
//					    $('select[name="bag_id"]').append(option);
//			        }else{
//			        	var option = '';	
//					    option += "<option value=''>请选择</option>";
//					    $('select[name="bag_id"]').empty();
//					    $('select[name="bag_id"]').append(option);
//			        	layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
//			        }
//		        }
//	        });
//      });

        <{if $info.is_all_channel == 2 }>
    	     $('.select_channel').hide();
    	<{/if}>
    	
    	$('#is_all_channel1').on('ifChecked', function(event){
        	$('.select_channel').hide();
        });
    
        $('#is_all_channel2').on('ifChecked', function(event){
        	$('.select_channel').show();
        });

        var is_same_accoun = $('select[name="is_same_accoun"]').val();
            if(is_same_accoun == 2){
        		$('#is_same_role').show();
        		$('#limit_time').show();
        	}
        	if(is_same_accoun == 1){
        		$('#is_same_role').hide();
        		$('#limit_time').hide();
        	}
        
        $('select[name="is_same_accoun"]').change(function(){
        	var is_same_accoun = $('select[name="is_same_accoun"]').val();
        	if(is_same_accoun == 2){
        		$('#is_same_role').show();
        		$('#limit_time').show();
        	}
        	if(is_same_accoun == 1){
        		$('#is_same_role').hide();
        		$('#limit_time').hide();
        	}
        	
        });
        
        
        $('button[name="sub"]').click(function(){      	
        	var classify = $('select[name="classify"]').val();
        	if(classify == ''){
        		layer.alert('请选择礼包类型', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var bag_id = $('input[name="bag_id"]').val();
        	if(bag_id == ''){
        		layer.alert('请填写礼包ID', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var code_num = $('input[name="code_num"]').val();
        	if(code_num == ''){
        		layer.alert('请填写生成数量', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	if(code_num > 20000){
        		layer.alert('一次最多生成20000个激活码', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	if(classify == 2 && code_num != 1){
        		layer.alert('通用礼包的生成数量固定为1', {icon: 2, skin: 'layui-layer-molv'});
        		$('input[name="code_num"]').val(1);
            	return false;
        	}
        	
        });
       
    });
    
    function searchChannel(){
    	layer.alert('禁止修改', {icon: 2, skin: 'layui-layer-molv'});
    	return false;
    	var g = $('input[name="g"]').val();
    	
    	var channel = $("input[name='channel_id[]']");
    	var channel_ids = '';
    	channel.each(function(i,o){
            var id = $(o).val();
            channel_ids = channel_ids +id + ',';
        })
    	channel_ids = channel_ids.substr(0,channel_ids.length-1);

    	
    	var url = '?r=channel/searchChannel&g='+g+'&channel_ids='+channel_ids;

        layer.open({
            type: 2,
            title: '选择渠道',
            shadeClose: true,
            shade: 0.3,
            area: ['50%', '80%'],
            content: url,
        });
    }
    
    function call_back(channelItem){
        var html = '';
        $.each(channelItem, function (index, item) {
            if (item.id != 'on') {
                html += '<div style="float: left;margin-right: 20px"><div class="ys-btn-close" style="color:red;top: 15px;left: 172px;">×</div>' +
                            '<input type="hidden" name="channel_id[]" value="' + item.id + '"/>' + item.name + ' </div>';
            }
        });
        $('#selected_group_channel').append(html);
        layer.closeAll('iframe');
    }
    
    $(function () {
        $(document).on("click", '.ys-btn-close', function (e) {
        	layer.alert('禁止删除', {icon: 2, skin: 'layui-layer-molv'});
    	    return false;
            $(this).parent().remove();
        })
    })
</script>